package com.ylbh.modules.cashaudit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.businessorder.vo.NewBusinessGoodsVO;
import com.ylbh.common.pojo.businessorder.vo.NewBusinessOrderDetailsVO;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditPassDTO;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditDTO;
import com.ylbh.common.pojo.cashaudit.dto.DiscountRecordDTO;
import com.ylbh.common.pojo.cashaudit.dto.MerchantIncomeListDTO;
import com.ylbh.common.pojo.cashaudit.vo.*;
import com.ylbh.common.utils.*;
import com.ylbh.modules.business.entity.ShoppingUser;
import com.ylbh.modules.businessorder.mapper.ShoppingBusinessOrderMapper;
import com.ylbh.modules.cashaudit.entity.BusinessWithRecord;
import com.ylbh.modules.cashaudit.mapper.BusinessWithRecordMapper;
import com.ylbh.modules.cashaudit.service.BusinessWithRecordService;
import com.ylbh.modules.sys.entity.SysUserEntity;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.ylbh.common.utils.DateHelper.getDateTime_IV;


@Service
public class BusinessWithRecordServiceImpl extends ServiceImpl<BusinessWithRecordMapper, BusinessWithRecord> implements BusinessWithRecordService {

    @Autowired
    private BusinessWithRecordMapper businessWithRecordMapper;

    @Autowired
    private ShoppingBusinessOrderMapper shoppingBusinessOrderMapper;

    @Value("${url.clientWithdrawalPushByOpenId}")
    private String clientWithdrawalPushByOpenId;

    /**
     * 提现审核列表
     * @param cashAuditDTO
     * @return
     */
    @Override
    public PageUtils queryCashAuditList(CashAuditDTO cashAuditDTO) {
        Page<Object> page = new Page<>(cashAuditDTO.getPage(), cashAuditDTO.getLimit());
        List<CashAuditListVO> auditList = businessWithRecordMapper.selectCashAuditList(cashAuditDTO, page);
        // 查询出平台可提现余额
        CashAuditVO balance = businessWithRecordMapper.selectCashAbleBalanceByStatus();
        CashAuditVO cashAuditVO = new CashAuditVO();
        if (null != balance) {
            cashAuditVO.setAllMoney(balance.getNotExtract().add(balance.getCommissionMoney()));
            cashAuditVO.setCommissionMoney(balance.getCommissionMoney());
            cashAuditVO.setNotExtract(balance.getNotExtract());
            for (CashAuditListVO v : auditList) {
                v.setCount(businessWithRecordMapper.selectCountById(Long.parseLong(v.getWithRecordId())));
                v.setWeekMoney(businessWithRecordMapper.selectWeekMoney(Long.parseLong(v.getWithRecordId())));
            }
        }
        cashAuditVO.setCashAuditListVO(auditList);
        Page<CashAuditVO> page1 = new Page<CashAuditVO>().setTotal(page.getTotal()).setRecords(Collections.singletonList(cashAuditVO));
        return new PageUtils(page1);
    }

    /**
     * 周内提现列表
     * @param cashAuditDTO
     * @return
     */
    @Override
    public PageUtils queryWeekAndMonthCashWithdrawalList(CashAuditDTO cashAuditDTO) {
        Page<Object> page = new Page<>(cashAuditDTO.getPage(), cashAuditDTO.getLimit());
        List<CashAuditListVO> withdrawalList = businessWithRecordMapper.selectWeekAndMonthCashWithdrawalList(cashAuditDTO, page);
        for (CashAuditListVO v : withdrawalList) {
            v.setCount(businessWithRecordMapper.selectCountById(Long.parseLong(v.getWithRecordId())));
            v.setWeekMoney(businessWithRecordMapper.selectWeekMoney(Long.parseLong(v.getWithRecordId())));
        }
        return new PageUtils(new Page<CashAuditListVO>().setTotal(page.getTotal()).setRecords(withdrawalList));
    }

    /**
     * 提现审核操作
     * @param
     * @return
     */
    @Override
    public void modifyCashAudit(CashAuditPassDTO cashAuditPassDTO) {
//        if (cashAuditPassDTO.getType() == 2){
//            cashAuditPassDTO.setBalanceId(new IdWorker().nextId());
//            cashAuditPassDTO.setDate(new Date());
//            SysUserEntity userEntity = ShiroUtils.getUserEntity();
//            cashAuditPassDTO.setCreateUserId(userEntity.getUserId());
//            cashAuditPassDTO.setChangeRemark(cashAuditPassDTO.getNoPass());
//            // 查询出后台操作人员的角色类型
//            // 如果userId为1，则表示为admin账号
//            int userType = 1;
//            if (cashAuditPassDTO.getCreateUserId() != 1) {
//                 userType = businessWithRecordMapper.selectAdminUserType(cashAuditPassDTO.getCreateUserId());
//            }
//            cashAuditPassDTO.setCreateUserType(userType);
//            // 查询用户的余额信息
//            ShoppingUser user = businessWithRecordMapper.selectUserByWithUserId(cashAuditPassDTO.getWithUserId());
//            // 状态0和2表示是银行卡和支付宝提现，基本上是订单提现
//            if (cashAuditPassDTO.getAccType() == 0 || cashAuditPassDTO.getAccType() == 3) {
//                cashAuditPassDTO.setCurrentAmount(user.getNotExtract().add(cashAuditPassDTO.getMoney()));
//            }
//            // 状态是1表示得佣金提现
//            if (cashAuditPassDTO.getAccType() == 1) {
//                cashAuditPassDTO.setCurrentAmount(user.getCommissionMoney().add(cashAuditPassDTO.getMoney()));
//            }
//            cashAuditPassDTO.setWithUserType(user.getUserType());
//            businessWithRecordMapper.insertBalanceLog(cashAuditPassDTO);
//        }
        if (cashAuditPassDTO.getType() == 1) {
            cashAuditPassDTO.setNoPass("提现金额将在2-3个工作日内返回到您的账户，请注意查收");
            businessWithRecordMapper.updateCashAudit(cashAuditPassDTO.getId(), cashAuditPassDTO.getType(), getDateTime_IV(new Date()), cashAuditPassDTO.getNoPass(), cashAuditPassDTO.getAccType());
        }else {
            businessWithRecordMapper.updateCashAudit(cashAuditPassDTO.getId(), cashAuditPassDTO.getType(), getDateTime_IV(new Date()), cashAuditPassDTO.getNoPass(), cashAuditPassDTO.getAccType());
//            if (StringUtils.isNotBlank(cashAuditPassDTO.getOrderNo())) {
//                List<CashWithdrawalJson> toList = FastJsonUtil.toList(cashAuditPassDTO.getOrderNo(), CashWithdrawalJson.class);
//                for (CashWithdrawalJson json : toList) {
//                    // 不通过将联盟店订单表中的提现记录改为未提现状态
//                    if (json.getType() == 1) {
//                        businessWithRecordMapper.updateBusinessOrder(json.getNo());
//                    }
//                    // 不通过将交易明细表中的提现记录改为未提现状态
//                    if (json.getType() == 2) {
//                        businessWithRecordMapper.updatePayInfo(json.getNo());
//                    }
//                }
//            }

        }

        // 提现审核公众号推送
        Map<String, String> map = new HashMap<>();
        map.put("accType", cashAuditPassDTO.getAccType().toString());
        map.put("cashRemarks", cashAuditPassDTO.getNoPass());
        if (cashAuditPassDTO.getType() == 1) {
            map.put("cashStatus", "2");
        } else {
            map.put("cashStatus", "5");
        }
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        map.put("money", cashAuditPassDTO.getMoney().toString());
        map.put("openId", "");
        map.put("realName", "");
        map.put("userId", cashAuditPassDTO.getWithUserId().toString());
        String s = HttpClientHelperUtils.sendHttpPosts(clientWithdrawalPushByOpenId, map);
        System.out.println(s);
    }

    /**
     * 提现详情
     * @param id
     * @return
     */
    @Override
    public DetailsOfPresentationVO getDetailsOfPresentation(Long id) {
        DetailsOfPresentationVO details = businessWithRecordMapper.selectDetailsOfPresentationById(id);
        details.setCount(businessWithRecordMapper.selectCountById(id));
        details.setWeekMoney(businessWithRecordMapper.selectWeekMoney(id));
        return details;
    }

    /**
     * 提现审核详情子订单信息
     * @param id
     * @return
     */
    @Override
    public PageUtils getSonOrderDetailsById(String id, PageDTO pageDTO) {
        Page<Object> page = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        List<String> list = businessWithRecordMapper.getSonOrderDetailsById(id, page);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<OrderNoVO> toList = null;
        if (list.size() > 0) {
            for (String s : list) {
                toList = FastJsonUtil.toList(s, OrderNoVO.class);
                for (OrderNoVO o : toList) {
                    if (null != o.getCreateTime())
                        o.setCreateTime(sdf.format(new Date(Long.parseLong(o.getCreateTime()))));
                }
            }
        }
        return new PageUtils(new Page<OrderNoVO>().setRecords(toList).setTotal(page.getTotal()));
    }

    /**
     * 商家收益列表
     * @param merchantIncomeListDTO
     * @return
     */
    @Override
    public PageUtils queryMerchantIncomeList(MerchantIncomeListDTO merchantIncomeListDTO) {
        Page<Object> page = new Page<>(merchantIncomeListDTO.getPage(), merchantIncomeListDTO.getLimit());
        List<MerchantIncomeListVO> incomeList = businessWithRecordMapper.selectMerchantIncomeList(merchantIncomeListDTO, page);
        BigDecimal Money = businessWithRecordMapper.selectTotalMoneyById(merchantIncomeListDTO.getId());
        CashAuditVO cashAuditVO = new CashAuditVO();
        // 商家收益总额
//        BigDecimal totalMoney = new BigDecimal("0.00");
//        for (Object b : Money) {
//            totalMoney = totalMoney.add((BigDecimal)b);
//        }
        // 推广可提现余额/已提现余额
        RecommendedBalanceVO balance = businessWithRecordMapper.selectRecommendedBalanceById(merchantIncomeListDTO.getId());
        cashAuditVO.setAllMoney(Money);
        cashAuditVO.setCashAuditListVO(incomeList);
//        cashAuditVO.setNotExtract(balance.getNotExtract());
        cashAuditVO.setCommissionMoney(balance.getCommissionMoney());
        cashAuditVO.setYesExtract(balance.getYesExtract());

        BigDecimal notExtractById = businessWithRecordMapper.selectNotExtractById(merchantIncomeListDTO.getId());// 未提现的金额
        cashAuditVO.setNotExtract(notExtractById);

        // 根据当前列表中的数据来查询出和订单详情中的支付金额和支付消耗券总量
        ArrayList<String> list = new ArrayList<>();
        for (MerchantIncomeListVO vo : incomeList) {
            if (!StringUtils.isEmpty(vo.getOrderId())) {
                list.add(vo.getOrderId());
            }
        }
        if (list.size() > 0) {
            // 根据订单id去查询统计总支付金额
            BigDecimal paymentAmount = businessWithRecordMapper.selectPaymentAmountById(list);
            // 根据订单id去查询统计总支付购物券
            Integer paymentVouchers = businessWithRecordMapper.selectPaymentVouchersById(list);
            cashAuditVO.setPaymentAmount(paymentAmount);
            cashAuditVO.setPaymentVouchers(paymentVouchers);
        }
        return new PageUtils(new Page<CashAuditVO>().setTotal(page.getTotal()).setRecords(Collections.singletonList(cashAuditVO)));
    }

    /**
     * 商家收益详情-线上
     * @param id
     */
    @Override
    public DetailsOfEarningsAndOnLineVO getDetailsOfEarningsAndOnLineById(Long id) {
        String goodsIds = businessWithRecordMapper.selectBusinessGoodsByOrderId(id);
        DetailsOfEarningsAndOnLineVO details = new DetailsOfEarningsAndOnLineVO();
        if (StringUtils.isNotBlank(goodsIds)) {
            String[] goodsId = goodsIds.split(",");
            for (String s : goodsId) {
                DetailsOfEarningsAndOnLineVO vo = businessWithRecordMapper.selectDetailsOfEarningsAndOnLineById(Long.parseLong(s));
                if (null != vo) {
                    if (StringUtils.isNotBlank(details.getGoodsName())) {
                        details.setGoodsName(details.getGoodsName() + ";" + vo.getGoodsName());
                    } else {
                        details.setGoodsName(vo.getGoodsName());
                    }
                    if (StringUtils.isNotBlank(details.getGoodsDesc())) {
                        details.setGoodsDesc(details.getGoodsDesc() + ";" + vo.getGoodsDesc());
                    } else {
                        details.setGoodsDesc(vo.getGoodsDesc());
                    }
                    details.setTrueName(vo.getTrueName());
                    details.setUserName(vo.getUserName());
                    details.setUserType(vo.getUserType());
                    if (StringUtils.isNotBlank(details.getMarketPrice())) {
                        details.setMarketPrice(details.getMarketPrice() + ";" + vo.getMarketPrice());
                    } else {
                        details.setMarketPrice(vo.getMarketPrice());
                    }
                    if (StringUtils.isNotBlank(details.getVipPrice())) {
                        details.setVipPrice(details.getVipPrice() + ";" + vo.getVipPrice());
                    } else {
                        details.setVipPrice(vo.getVipPrice());
                    }
                    if (StringUtils.isNotBlank(details.getSaleCount())) {
                        details.setSaleCount(details.getSaleCount() + ";" + vo.getSaleCount());
                    } else {
                        details.setSaleCount(vo.getSaleCount());
                    }
                    details.setIsSale(vo.getIsSale());
                    details.setIsCommission(vo.getIsCommission());
                    if (StringUtils.isNotBlank(details.getCommission())) {
                        details.setCommission(details.getCommission() + ";" + vo.getCommission());
                    } else {
                        details.setCommission(vo.getCommission());
                    }
                    details.setGoodsStatus(vo.getGoodsStatus());
                    details.setCreateTime(vo.getCreateTime());
                    details.setSaleTime(vo.getSaleTime());
                    details.setShelvesTime(vo.getShelvesTime());
                    if (StringUtils.isNotBlank(details.getStatusRemarks())) {
                        details.setStatusRemarks(details.getStatusRemarks() + ";" + vo.getStatusRemarks());
                    } else {
                        details.setStatusRemarks(vo.getStatusRemarks());
                    }
                    details.setDistributionTypes(details.getDistributionTypes() + ";" + vo.getDistributionTypes());
                    if (StringUtils.isNotBlank(details.getGoodsStock())) {
                        details.setGoodsStock(details.getGoodsStock() + ";" + vo.getGoodsStock());
                    } else {
                        details.setGoodsStock(vo.getGoodsStock());
                    }
                    if (StringUtils.isNotBlank(details.getClickCount())) {
                        details.setClickCount(details.getClickCount() + ";" + vo.getClickCount());
                    } else {
                        details.setClickCount(vo.getClickCount());
                    }
                }
            }
        }
        return details;
    }

    /**
     * 商家收益详情-线下
     * @param id
     */
    @Override
    public DetailsOfEarningsAndUnderTheLineVO getDetailsOfEarningsAndUnderTheLineById(Long id) {
        return businessWithRecordMapper.selectDetailsOfEarningsAndUnderTheLineById(id);
    }

    /**
     * 商家收益详情-推广
     * @param id
     */
    @Override
    public DetailsOfEarningsAndExtensionVO getDetailsOfEarningsAndExtensionById(Long id) {
        return businessWithRecordMapper.selectDetailsOfEarningsAndExtensionById(id);
    }

    /**
     * 待提现审核的记录数
     * @return
     */
    @Override
    public Integer queryWithRecordCount() {
        return businessWithRecordMapper.selectWithRecordCount();
    }

    /**
     * 提现记录
     * @param discountRecordDTO
     * @return
     */
    @Override
    public PageUtils queryDiscountRecordList(DiscountRecordDTO discountRecordDTO) {
        Page<Object> page = new Page<>(discountRecordDTO.getPage(), discountRecordDTO.getLimit());
        List<DiscountRecordVO> list = businessWithRecordMapper.selectDiscountRecordList(discountRecordDTO, page);
        for (DiscountRecordVO vo : list) {
            if (StringUtils.isNotBlank(vo.getOrderNo())) {
                List<CashWithdrawalJson> toList = FastJsonUtil.toList(vo.getOrderNo(), CashWithdrawalJson.class);
                ArrayList<SonDiscountRecordVO> sonList = new ArrayList<>();
                for (CashWithdrawalJson jo : toList) {
                    if (jo.getType() == 1) {
                        // 线上订单
                        SonDiscountRecordVO son = businessWithRecordMapper.selectSonDiscountRecord(jo.getNo());
                        if (null != son)
                            son.setMoney(jo.getMoney());
                            sonList.add(son);
                    }
                    if (jo.getType() == 2) {
                        // 买单
                        SonDiscountRecordVO son = businessWithRecordMapper.selectSonDiscountRecords(jo.getNo());
                        if (null != son)
                            son.setMoney(jo.getMoney());
                            sonList.add(son);
                    }
                }
                vo.setList(sonList);
            }
        }
        return new PageUtils(new Page<DiscountRecordVO>().setTotal(page.getTotal()).setRecords(list));
    }

    @Override
    public void cashAuditExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        String keywords = request.getParameter("keywords");
        String accType = request.getParameter("accType");
        String cashStatus = request.getParameter("cashStatus");
        List<CashAuditExcel> list = businessWithRecordMapper.cashAuditExcel(keywords, accType, cashStatus);
        ExcelUtils.exportExcel(list, "提现审核", "", CashAuditExcel.class, System.currentTimeMillis() + ".xls", response);
    }

    /**
     * 提现记录导出
     * @param request
     * @param response
     */
    @Override
    public void cashWithdrawalRecordExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
        SXSSFSheet sheet = sxssfWorkbook.createSheet("提现记录");
        SXSSFRow headRow = sheet.createRow(0);

        headRow.createCell(0).setCellValue("提现类型");
        headRow.createCell(1).setCellValue("提现账号");
        headRow.createCell(2).setCellValue("提现状态");
        headRow.createCell(3).setCellValue("提现时间");
        headRow.createCell(4).setCellValue("提现金额");
        headRow.createCell(5).setCellValue("提现名称");
        headRow.createCell(6).setCellValue("用户类型");
        headRow.createCell(7).setCellValue("提现来源");
        headRow.createCell(8).setCellValue("交易单号");
        headRow.createCell(9).setCellValue("买家账号");
        headRow.createCell(10).setCellValue("买家名称");
        headRow.createCell(11).setCellValue("商家账号");
        headRow.createCell(12).setCellValue("商家名称");
        headRow.createCell(13).setCellValue("订单金额");
        headRow.createCell(14).setCellValue("订单时间");

        // 根据时间来筛选提现记录
        List<DiscountRecordVO> list = businessWithRecordMapper.selectCashWithdrawalRecordByTime(request.getParameter("startTime"), request.getParameter("endTime"), request.getParameter("userName"));
        int count = 1;
        int a = 0;
        for (DiscountRecordVO vo : list) {
            if (StringUtils.isNotBlank(vo.getOrderNo())) {
                List<CashWithdrawalJson> toList = FastJsonUtil.toList(vo.getOrderNo(), CashWithdrawalJson.class);
                ArrayList<SonDiscountRecordVO> sonList = new ArrayList<>();
                for (CashWithdrawalJson jo : toList) {
                    if (jo.getType() == 1) {
                        // 线上订单
                        SonDiscountRecordVO son = businessWithRecordMapper.selectSonDiscountRecord(jo.getNo());
                        if (null != son)
                            son.setMoney(jo.getMoney());
                        sonList.add(son);
                    }
                    if (jo.getType() == 2) {
                        // 买单
                        SonDiscountRecordVO son = businessWithRecordMapper.selectSonDiscountRecords(jo.getNo());
                        if (null != son)
                            son.setMoney(jo.getMoney());
                        sonList.add(son);
                    }
                }
                vo.setList(sonList);
            }
            if (null != vo.getList() && vo.getList().size() > 1) {
                CellRangeAddress region1 = new CellRangeAddress(count, count + vo.getList().size() - 1, 0, 0);
                CellRangeAddress region2 = new CellRangeAddress(count, count + vo.getList().size() - 1, 1, 1);
                CellRangeAddress region3 = new CellRangeAddress(count, count + vo.getList().size() - 1, 2, 2);
                CellRangeAddress region4 = new CellRangeAddress(count, count + vo.getList().size() - 1, 3, 3);
                CellRangeAddress region5 = new CellRangeAddress(count, count + vo.getList().size() - 1, 4, 4);
                CellRangeAddress region6 = new CellRangeAddress(count, count + vo.getList().size() - 1, 5, 5);
                CellRangeAddress region7 = new CellRangeAddress(count, count + vo.getList().size() - 1, 6, 6);
                CellRangeAddress region8 = new CellRangeAddress(count, count + vo.getList().size() - 1, 7, 7);
                count = count + vo.getList().size();
                sheet.addMergedRegion(region1);
                sheet.addMergedRegion(region2);
                sheet.addMergedRegion(region3);
                sheet.addMergedRegion(region4);
                sheet.addMergedRegion(region5);
                sheet.addMergedRegion(region6);
                sheet.addMergedRegion(region7);
                sheet.addMergedRegion(region8);
            } else {
                if (null != vo.getList())
                    count = count + vo.getList().size();
                else {
                    count = count + 1;
                }
            }
            SXSSFRow dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
            dataRow.createCell(0).setCellValue(vo.getAccType() == 0 ? "商家端银行卡" : (vo.getAccType() == 1 ? "用户端微信" : (
                    vo.getAccType() == 2 ? "公司手动打款" : (vo.getAccType() == 3 ? "支付宝提现" : "")
                    )));
            dataRow.createCell(1).setCellValue(vo.getAccountNo());
            dataRow.createCell(2).setCellValue(vo.getCashSatus() == 0 ? "提现失败" : (vo.getCashSatus() == 1 ? "提现成功" : (vo.getCashSatus() == 2 ? "提现中" : (
                    vo.getCashSatus() == 3 ? "待审核" : (vo.getCashSatus() == 4 ? "已审核" : (vo.getCashSatus() == 5 ? "审核不通过" : ""))
                    ))));
            dataRow.createCell(3).setCellValue(sdf.format(vo.getCreateTime()));
            dataRow.createCell(4).setCellValue(vo.getMoney().toString());
            dataRow.createCell(5).setCellValue(vo.getWithUserName());
            dataRow.createCell(6).setCellValue(vo.getWithUserType() == 1 ? "运营商" : (vo.getWithUserType() == 2 ? "普通联盟店" : (vo.getWithUserType() == 3 ? "消费者" : (
                    vo.getWithUserType() == 4 ? "VIP会员" : (vo.getWithUserType() == 5 ? "中级版联盟店" : (vo.getWithUserType() == 6 ? "高级版联盟店" : (
                            vo.getWithUserType() == 7 ? "城市合伙人" : (vo.getWithUserType() == 8 ? "城市合伙人联盟店" : "")
                    )))))));
            dataRow.createCell(7).setCellValue(vo.getWithSrc() == 0 ? "安卓" : (vo.getWithSrc() == 1 ? "苹果" : (
                    vo.getWithSrc() == 2 ? "小程序" : (vo.getWithSrc() == 3 ? "后台" : "")
                    )));
            if (null != vo.getList()) {
                for (int k = 0; k < vo.getList().size(); k++) {
                    if (k > 0) {
                        dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
                    }
                    dataRow.createCell(8).setCellValue(vo.getList().get(k).getPayNo());
                    dataRow.createCell(9).setCellValue(vo.getList().get(k).getPayUserName());
                    dataRow.createCell(10).setCellValue(vo.getList().get(k).getPayTrueName());
                    dataRow.createCell(11).setCellValue(vo.getList().get(k).getStoreUserName());
                    dataRow.createCell(12).setCellValue(vo.getList().get(k).getStoreTrueName());
                    dataRow.createCell(13).setCellValue(vo.getList().get(k).getMoney().toString());
                    dataRow.createCell(14).setCellValue(sdf.format(vo.getList().get(k).getCreateTime()));
                }
            }
        }
        // 下载导出
        // 设置头信息
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/vnd.ms-excel");
        //一定要设置成xlsx格式
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(System.currentTimeMillis() + ".xls", "UTF-8"));
        //创建一个输出流
        ServletOutputStream outputStream = response.getOutputStream();
        //写入数据
        sxssfWorkbook.write(outputStream);

        // 关闭
        outputStream.close();
        sxssfWorkbook.close();
    }

    /**
     * 提现详情
     * @param no
     * @return
     */
    @Override
    public NewBusinessOrderDetailsVO getOrderDetails(String no, Integer type) {
        NewBusinessOrderDetailsVO vo = null;
        if (type == 1) {
            vo = shoppingBusinessOrderMapper.selectNewBusinessOrderByNo(no);
            vo.setPlatformMoney((vo.getTotalMoney().subtract(vo.getDeliverMoney()).subtract(vo.getServiceMoney())).multiply(vo.getStoreCommission().divide(new BigDecimal(100))));
            // 查询该笔订单里的商品
            List<NewBusinessGoodsVO> list = shoppingBusinessOrderMapper.selectNewOrderGoods(vo.getOrderNo());
            vo.setList(list);
        } else {
            vo =shoppingBusinessOrderMapper.selectNewPayInfoById(no);
            if (null != vo) {
                vo.setPlatformMoney((vo.getTotalMoney().subtract(vo.getServiceMoney())).multiply(vo.getStoreCommission().divide(new BigDecimal(100))));
            }
        }
        return vo;
    }
}
